class tongue extends eui.Component {
	public constructor() {
		super();
		this.init();
	}
	public isUsed = false;
	//舌头图片
	private tongueObj = new eui.Image();
	//舌结图片
	private tongueKnot = new eui.Image();
	/**线数据 坐标*角度*宽度 */
	public lineData: any = null;
	public lineMax: any = null;
	public linebili: any = null;
	public userOneId: any = null;
	public userTwoId: any = null;

	public texture0;
	public texture1;
	public texture2;
	public texture3;
	/**初始化 */
	public init() {
		this.tongueObjInit();
		this.tongueKnotInit();
		this.height = 100;
		this.visible = false;
		this.texture0 = RES.getRes("shetou_0");

		this.texture1 = RES.getRes("shetou_1");
		this.texture2 = RES.getRes("shetou_2");
		this.texture3 = RES.getRes("shetou_3");

	}
	//舌头初始化 
	private tongueObjInit() {
		//this.tongueObj.texture = RES.getRes("shetou_0");
		this.tongueObj.texture = this.texture0;
		this.addChild(this.tongueObj);
		this.tongueObj.anchorOffsetY = this.tongueObj.height / 2;
		this.tongueObj.anchorOffsetX = this.tongueObj.width / 2;
		this.tongueObj.x = this.tongueObj.y = 0;
	}
	//舌结初始化
	private tongueKnotInit() {
		this.tongueKnot.texture = RES.getRes("shejie");
		this.addChild(this.tongueKnot);
		this.tongueKnot.anchorOffsetY = this.tongueKnot.height / 2;
		this.tongueKnot.anchorOffsetX = this.tongueKnot.width / 2;
		this.tongueKnot.x = this.tongueKnot.y = 0;
	}
	//舌头的出生 给定出现的位置、使用舌头的两只青蛙id以及舌头的最大长度
	public born(lineData: any, userOneId: any, userTwoId: any) {
		this.lineData = lineData;
		this.userOneId = userOneId;
		this.userTwoId = userTwoId;
		this.isUsed = this.visible = true;
		this.lineUpdata();
	}
	//重置舌头
	public reset() {
		this.lineData = null;
		this.userOneId = null;
		this.userTwoId = null;
		this.visible = this.isUsed = false;
	}
	/**实时改变舌头的状态 */
	public updateTongueData(lineData, linemax) {//00修改舌头更新，添加舌头最大长度

		this.lineData.lineLenth = lineData.lineLenth;
		this.lineData.postion = lineData.postion;
		this.lineData.rotation = lineData.rotation;
		this.lineData.type = lineData.type;
		this.lineMax = linemax;
		this.lineUpdata();
	}
	/**随舌长改变舌头粗细 */
	private TongueProportion(textureName: string) {
		if (textureName == "shetou_0") {
			this.tongueObj.texture = this.texture0;
		} else if (textureName == "shetou_1") {
			this.tongueObj.texture = this.texture1;
		} else if (textureName == "shetou_2") {
			this.tongueObj.texture = this.texture2;
		} else if (textureName == "shetou_3") {
			this.tongueObj.texture = this.texture3;
		}
		//this.tongueObj.texture = RES.getRes(textureName);
		//this.width = this.tongueObj.width = this.lineData.lineLenth - 100;
		if (this.lineMax > this.tongueObj.width) {
			this.linebili = (this.lineMax - this.tongueObj.width) / this.lineMax;
			this.linebili += 0.6;
			if (this.linebili <= 0.1) {
				this.linebili = 0.1;
			}
		}
		this.tongueObj.height = 24 * this.linebili;
		this.tongueObj.anchorOffsetY = this.tongueObj.height / 2;
	}
	/**调整线的位置、角度 */
	private lineUpdata() {
		if (this.lineData.type == 1) {
			this.alpha = 0.05;
		} else {
			this.alpha = 1;
		}
		this.x = this.lineData.postion.x;
		this.y = this.lineData.postion.y;
		this.rotation = this.lineData.rotation + 90;
		//this.width = this.tongueObj.width = this.lineData.lineLenth - 100;//00修改,当this.lineData.lineLenth<100时，会导致新生成的舌头很长
		if (this.lineData.lineLenth > 80) {
			this.lineData.lineLenth -= 80;
		}
		this.tongueObj.width = this.lineData.lineLenth;
		this.width = this.tongueObj.width;
		this.tongueObj.anchorOffsetX = this.tongueObj.width / 2;
		if (this.tongueObj.width <= this.lineMax * 0.5) {//00修改按百分比改变舌头粗细
			this.tongueObj.texture = this.texture0;
			this.tongueObj.height = 24;
			this.tongueObj.anchorOffsetY = this.tongueObj.height / 2;
		}
		else if (this.tongueObj.width <= this.lineMax * 0.65) {
			this.TongueProportion("shetou_1");
		}
		else if (this.tongueObj.width <= this.lineMax * 0.8) {
			this.TongueProportion("shetou_2");
		}
		else {
			this.TongueProportion("shetou_3");
		}
	}
}